//
//  WKStock_Chart_Detail_Type_Section_View.m
//  XTXOneToOne
//
//  Created by Canny on 2018/11/20.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "WKStock_Chart_Detail_Type_Section_View.h"
#import "WKStockHeaderview_Type_One.h"
#import "WKStockHeaderview_Type_Two.h"

@interface WKStock_Chart_Detail_Type_Section_View ()

@property (nonatomic,strong)WKStockHeaderview_Type_One * view_Type_1;
@property (nonatomic,strong)WKStockHeaderview_Type_Two * view_Type_2;
@property (nonatomic,strong)UIView * view_Type_3;


@end

@implementation WKStock_Chart_Detail_Type_Section_View

#pragma mark - 初始化
-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithReuseIdentifier:reuseIdentifier];
    
    if (self)
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        [self createUI];
    }
    
    return self;
}

#pragma mark - 创建UI
-(void)createUI
{
    self.backgroundColor = [UIColor whiteColor];

    //深度
    [self depthButton];
    
    //成交
    [self dealButton];
    
    //简介
    [self introButton];
    
    //分割线
//    [self lineView];
    
    //
    [self view_Type_1];
    
    [self view_Type_2];
}

-(WKSectionSelectedButton *)depthButton{
    if (_depthButton==nil)
    {
        _depthButton=[WKSectionSelectedButton buttonWithType:UIButtonTypeCustom];
        
        [_depthButton setTitle:@"深度" forState:UIControlStateNormal];
        
        [_depthButton setTitleColor:ThemeColor forState:UIControlStateNormal];
        
        [_depthButton setTitleColor:ThemeColor forState:UIControlStateSelected];
        
        _depthButton.titleLabel.font=[UIFont systemFontOfSize:16];
        
        _depthButton.selected=YES;
        
        [_depthButton addTarget:self action:@selector(depth_Button_Event:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:_depthButton];
        
        [_depthButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.mas_left);
            make.width.mas_equalTo(G_SCREENWIDTH/3.0);
            make.top.equalTo(self);
            make.height.mas_equalTo(50);

        }];
    }
    
    return _depthButton;
}

#pragma mark - 成交按钮
-(WKSectionSelectedButton *)dealButton
{
    if (_dealButton==nil)
    {
        _dealButton=[WKSectionSelectedButton buttonWithType:UIButtonTypeCustom];
        
        [_dealButton setTitle:@"成交" forState:UIControlStateNormal];
        
        [_dealButton setTitleColor:ThemeColor forState:UIControlStateNormal];
        
        [_dealButton setTitleColor:ThemeColor forState:UIControlStateSelected];
        
        _dealButton.titleLabel.font=[UIFont systemFontOfSize:16];
        
        _dealButton.selected=YES;
        
        [_dealButton addTarget:self action:@selector(deal_Button_Event:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:_dealButton];
        [_dealButton setSelectedHidden:YES];
        
        [_dealButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.mas_left).offset(G_SCREENWIDTH/3.0);
            make.width.mas_equalTo(G_SCREENWIDTH/3.0);
            make.top.equalTo(self);
            make.height.mas_equalTo(50);

        }];
    }
    
    return _dealButton;
    
}

#pragma mark - 简介按钮
-(WKSectionSelectedButton *)introButton
{
    if (_introButton==nil)
    {
        _introButton=[WKSectionSelectedButton buttonWithType:UIButtonTypeCustom];
        
        [_introButton setTitle:@"简介" forState:UIControlStateNormal];
        
        [_introButton setTitleColor:ThemeColor forState:UIControlStateNormal];
        
        [_introButton setTitleColor:ThemeColor forState:UIControlStateSelected];
        
        _introButton.titleLabel.font=[UIFont systemFontOfSize:16];
        
        [_introButton addTarget:self action:@selector(intro_Button_Event:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:_introButton];
        [_introButton setSelectedHidden:YES];

        [_introButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.equalTo(self.mas_right).offset(0);
            make.width.mas_equalTo(G_SCREENWIDTH/3.0);
            make.top.equalTo(self);
            make.height.mas_equalTo(50);
        }];
    }
    
    return _introButton;
    
}

#pragma mark - 分割线
-(UIView *)lineView
{
    if (_lineView==nil)
    {
        _lineView=[[UIView alloc] init];
        
        _lineView.backgroundColor=RGB(220,220,220);
        
        [self.contentView addSubview:_lineView];
        
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.bottom.equalTo(self.contentView.mas_bottom);
            
            make.height.equalTo(@2.0);
            
            make.left.equalTo(@0);
            
            make.width.equalTo(@(G_SCREENWIDTH));
        }];
    }
    
    return _lineView;
}

#pragma mark - 简介按钮 点击事件
-(void)intro_Button_Event:(UIButton *)sender
{
    self.introButton.selected=YES;
    self.dealButton.selected=NO;
    self.depthButton.selected=NO;
    
    [self.dealButton setSelectedHidden:YES];
    [self.introButton setSelectedHidden:NO];
    [self.depthButton setSelectedHidden:YES];

    if (self.itemBlock)
    {
        self.itemBlock(3);
    }
}

#pragma mark - 成交按钮 点击事件
-(void)deal_Button_Event:(UIButton *)sender
{
    [self.dealButton setSelectedHidden:NO];
    [self.introButton setSelectedHidden:YES];
    [self.depthButton setSelectedHidden:YES];
    
    self.dealButton.selected=YES;
    self.introButton.selected=NO;
    self.depthButton.selected=NO;

    
    if (self.itemBlock)
    {
        self.itemBlock(2);
    }
}

-(void)depth_Button_Event:(UIButton *)sender
{
    self.depthButton.selected=YES;
    self.introButton.selected=NO;
    self.dealButton.selected=NO;
    
    [self.dealButton setSelectedHidden:YES];
    [self.introButton setSelectedHidden:YES];
    [self.depthButton setSelectedHidden:NO];
    
   
    
    if (self.itemBlock)
    {
        self.itemBlock(1);
    }
}



+(CGFloat)computeHeight:(NSInteger)type{
    if (type == 3) {
        return 50;
    }
    return 80;
}


-(void)relayOutUIWithType:(NSInteger)type{
    
    if (type == 1) {
        
        self.view_Type_1.hidden = NO;
        self.view_Type_2.hidden = YES;
        
    }else if (type == 2){
        
        self.view_Type_1.hidden = YES;
        self.view_Type_2.hidden = NO;
        
    }else if (type == 3){
        
        self.view_Type_1.hidden = YES;
        self.view_Type_2.hidden = YES;
        
    }
    
}

-(WKStockHeaderview_Type_One *)view_Type_1{
    if (_view_Type_1 == nil) {
        _view_Type_1 = [[WKStockHeaderview_Type_One alloc]init];
        [self.contentView addSubview:_view_Type_1];
        
        [_view_Type_1 mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.bottom.equalTo(self.contentView.mas_bottom);
            
            make.top.equalTo(self.contentView.mas_top).offset(50);
            make.left.equalTo(@0);
            
            make.width.equalTo(@(G_SCREENWIDTH));
        }];
        
    }
    return _view_Type_1;
}


-(WKStockHeaderview_Type_Two *)view_Type_2{
    if (_view_Type_2 == nil) {
        _view_Type_2 = [[WKStockHeaderview_Type_Two alloc]init];
        [self.contentView addSubview:_view_Type_2];
        
        [_view_Type_2 mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.bottom.equalTo(self.contentView.mas_bottom);
            
            make.top.equalTo(self.contentView.mas_top).offset(50);
            
            make.left.equalTo(@0);
            
            make.width.equalTo(@(G_SCREENWIDTH));
        }];
        
    }
    return _view_Type_2;
}

@end

